/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logical;

/**
 *
 * @author julien
 */
public class Atom extends LogicalElement {

    private String alphabeticalSymbol; // Symbole pour la saisie de formule plus rapide et le format Latex
    private int idNumber; // Identifiant numérique pour SAT
    private String literal; // Traduction littérale de l'atome

    // Constructeur sans utilisation du Not (Pas de not par défaut)
    public Atom(String alphabeticalSymbol, String literal) {
        this.alphabeticalSymbol = alphabeticalSymbol;
        this.literal = literal;
        this.negate = false;
        this.idNumber = alphabeticalSymbol.hashCode(); // Chaque nouvel atome aura un identifiant unique
    }

    //Constructyeur avec utilisation du Not
    // True pour Not(Atome), False pour (Atome)
    public Atom(String alphabeticalSymbol, String litteral, boolean negate) {
        this.alphabeticalSymbol = alphabeticalSymbol;
        this.literal = litteral;
        this.negate = negate;
        this.idNumber = alphabeticalSymbol.hashCode(); // Chaque nouvel atome aura un identifiant unique
    }
 
    @Override
    public String toString() {
        if (negate) {
            return "No " + literal;
        }
        return literal;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Atom other = (Atom) obj;
        if (this.idNumber != other.idNumber) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return idNumber;
    }

    @Override
    public String getLiteralTranslation() {
        if (negate) {
            return "No " + literal;
        }
        return literal;
    }

    @Override
    public String getLatexTranslation() {
        if (negate) {
            return "(NOT " + alphabeticalSymbol +")";
        }
        return alphabeticalSymbol;
    }

    @Override
    public String getSATTranslation() {
        if (negate) {
            return "-" + idNumber;
        }
        return ""+idNumber;
    }

    @Override
    public Atom getCNFForm() {
        return this ;
    }

}
